package vashion.azeroth.task.util;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class AsyncTaskExecutor {

    private static final int threadCount = 20 ;
    private static final ExecutorService pool = Executors.newFixedThreadPool(threadCount);

    /**
     * 增加异步任务(无需返回结果)
     * @param task 需运行的任务
     */
    public static void submit(Runnable task) {
        pool.submit(task);
    }

    /**
     * 嘿,没事儿别调用这个方法
     */
    public static void shutdown() {
        pool.shutdown();
    }

    /**
     * 增加异步任务(有返回结果)
     * @param task 需运行的任务
     * @result Future<T> 用于取得任务的返回结果
     *         可以用 future.get方法读取
     */
    public static <T> Future<T> submit(Callable<T> task) {
        return pool.submit(task);
    }

}
